package cn.fzu.frame;

import cn.fzu.menu.MineMenuBar;
import cn.fzu.panel.MineField;
import cn.fzu.panel.MineState;
import cn.fzu.util.Tools;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * ClassName : cn.fzu.frame.StartFrame
 * Desc : 扫雷主窗口
 *
 * @author : LINPQ
 * @date : 2021/3/27 14:38
 */
public class StartFrame extends JFrame {

    private MineMenuBar mineMenuBar;
    private MineState mineState;
    private MineField mineField;

    private Timer timer;
    int time = 0;

    public StartFrame(){
        //标题
        this.setTitle("专业扫雷一百年，2022-04-22 林鹏群");
        //位置
        this.setLocation(500,500);
        //布局 边框布局
        this.setLayout(new BorderLayout());

        init();

        //设置关闭
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        //扫雷图标
        this.setIconImage(new ImageIcon("./picture/icon.gif").getImage());

        //设置大小不可改变
        this.setResizable(false);
        //设置自适应大小
        this.pack();
        //设置可见
        this.setVisible(true);

    }

    public void init(){

        timer = new Timer(1000, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                mineState.setTime(time++);
            }
        });

        mineMenuBar = new MineMenuBar(this);
        this.setJMenuBar(mineMenuBar);

        mineState = new MineState(this);
        this.add(mineState,BorderLayout.NORTH);

        mineField = new MineField(this);
        this.add(mineField,BorderLayout.CENTER);


    }


    public void restart(){
        this.remove(mineState);
        this.remove(mineField);

        mineState = new MineState(this);
        this.add(mineState,BorderLayout.NORTH);

        mineField = new MineField(this);
        this.add(mineField,BorderLayout.CENTER);

        pack();
    }

    public static void main(String[] args) {
        StartFrame startFrame = new StartFrame();

    }


    public MineMenuBar getMineMenuBar() {
        return mineMenuBar;
    }

    public void setMineMenuBar(MineMenuBar mineMenuBar) {
        this.mineMenuBar = mineMenuBar;
    }

    public MineState getMineState() {
        return mineState;
    }

    public void setMineState(MineState mineState) {
        this.mineState = mineState;
    }

    public MineField getMineField() {
        return mineField;
    }

    public void setMineField(MineField mineField) {
        this.mineField = mineField;
    }

    public Timer getTimer() {
        return timer;
    }

    public void setTimer(Timer timer) {
        this.timer = timer;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }
}
